package com.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionUtil {

	private Connection conn=null;
	
	/**
	 * 获取数据库连接
	 * @return
	 * @throws ClassNotFoundException
	 * @throws SQLException
	 */
	public Connection getConnection() throws ClassNotFoundException, SQLException
	{
		Class.forName("com.mysql.jdbc.Driver");
		String url="jdbc:mysql://127.0.0.1:3306/studydb?useUnicode=true&amp;characterEncoding=utf-8";
		String user="root";
		String pwd="root123";
		conn=DriverManager.getConnection(url, user, pwd);
		return conn;
	}
	
	public void close() throws SQLException
	{
		conn.close();
	}
	
	
	
	
}
